//
//  BaseViewController.m
//  Zaker
//
//  Created by 赵磊 on 16/3/7.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "BaseViewController.h"

@interface BaseViewController ()

@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.navigationController.navigationBar.translucent = NO;
    //self.view.backgroundColor = [UIColor whiteColor];
    
    self.tabBarController.tabBar.hidden = YES;
    
     //self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"iconfont-zuojiantou-2"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(leftAction:)];
    
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"iconfont-zuojiantou-2.jpg"] forBarMetrics:UIBarMetricsCompactPrompt];
    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)forBarMetrics:UIBarMetricsDefault];//导航条返回键带的首页 让他消失
    
    //背景颜色
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.890 green:0.161 blue:0.188 alpha:1.000];
    
    //标题颜色
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18],NSForegroundColorAttributeName:[UIColor whiteColor]}];
    
    [self creatNight];
}

- (void)creatNight
{
    //监听中心,监听后面发来的信息
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeColor:) name:@"change" object:nil];
    
    //从night中取出储存的字符串(yes,no)
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString *passWord = [user objectForKey:@"night"];
    
    if ([passWord isEqualToString:@"yes"]) {
        
//        [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:0 / 255. green:30 / 255. blue:60 / 255. alpha:1]];
//        [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18],NSForegroundColorAttributeName:[UIColor whiteColor]}];
        self.tabBarController.tabBar.barTintColor = [UIColor colorWithRed:0 / 255. green:30 / 255. blue:60 / 255. alpha:1];
        self.view.backgroundColor = [UIColor colorWithRed:0 / 255. green:30 / 255. blue:60 / 255. alpha:1];
    } else {
//        self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
//        //更改导航栏标题字体颜色大小
//        [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18],NSForegroundColorAttributeName:[UIColor blackColor]}];
        self.tabBarController.tabBar.barTintColor = [UIColor whiteColor];
        //self.view.backgroundColor = [UIColor whiteColor];
    }
}
 
#pragma mark - defaultCenter方法
- (void)changeColor:(NSNotification *)center
{
    /*改变背景*/
//    [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:0 / 255. green:30 / 255. blue:60 / 255. alpha:1]];
//    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18],NSForegroundColorAttributeName:[UIColor blackColor]}];
    self.tabBarController.tabBar.barTintColor = [UIColor colorWithRed:0 / 255. green:30 / 255. blue:60 / 255. alpha:1];
    self.view.backgroundColor = [UIColor colorWithRed:0 / 255. green:30 / 255. blue:60 / 255. alpha:1];
    
    //找到字符串
    NSString *passWord = [center object];
    
    //消息中心发出消息NSUserDefaults将object中的字符串存入night中
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    [user setObject:passWord forKey:@"night"];
    
    //判断是yes还是no,yes的话改变背景颜色
    if ([passWord isEqualToString:@"no"]) {
//        self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
//        [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18],NSForegroundColorAttributeName:[UIColor whiteColor]}];
        self.tabBarController.tabBar.barTintColor = [UIColor whiteColor];
        //self.view.backgroundColor = [UIColor whiteColor];
    }
}
- (void)loadMBProgress
{
    self.hud = [[MBProgressHUD alloc] initWithView:self.view];
    
    self.hud.dimBackground = NO;
    //设置对话框文字
    self.hud.labelText = @"loading";
    self.hud.minShowTime = 50;
    self.hud.activityIndicatorColor = [UIColor whiteColor];
    self.hud.labelColor = [UIColor whiteColor];
    self.hud.minSize = CGSizeMake(10, 10);
    
    [self.view addSubview:self.hud];
    [self.hud showAnimated:YES whileExecutingBlock:^{
        //对话框显示时需要执行的操作
        sleep(1);
    } completionBlock:^{
        //操作执行完后取消对话框
        [self.hud removeFromSuperview];
      
        self.hud = nil;
    }];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
